package com.aaa.ssm.controller;

import com.aaa.ssm.util.CustomException;
import com.aaa.ssm.util.Result;
import com.aaa.ssm.util.ResultUtil;
import org.apache.ibatis.jdbc.Null;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @FileName: GlobalExceptionHandler
 * @Description:
 * @Author: ghz
 * @CreateTime:2025/8/22 16:27
 * @Version:1.0.0
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 通用的处理异常的方法
     * @param e
     * @return
     */
    @ExceptionHandler
    public Result handlerException(Exception e){
         e.printStackTrace();
        if (e instanceof CustomException){
            CustomException customException = (CustomException) e;
            return new Result<>(customException.getErrorCode(),customException.getErrorMessage(),"自定义异常");
        }
        return ResultUtil.fail(e.getClass().getName());
    }
}
